
class Scanner {

Scanner ( String  input )
{
    expr = input.toCharArray();
    length = expr.length;
    start = 0;
}

public double      get_attribute ()       { return  last_attribute; }   

private double  attribute;
private double  last_attribute;
private char[]  expr;
private int     start;
private int     length;

public 
short get ()
{
    short    token;
    int      end; 

//  System.out.println ( expr );

    while ( start < length  &&  Character.isWhitespace ( expr [start] ) ) {
        ++start;
    }                       
    last_attribute = attribute; 
                        
    if ( start >= length ) {
        token = SlkConstants.END_OF_SLK_INPUT_;
    } else if ( Character.isDigit ( expr [start] )  ||  expr [start] == '.' ) {
        token = SlkConstants.NUMBER_;
        end = start;
        while ( Character.isDigit ( expr [end] )  ||  expr [end] == '.' ) {
            ++end;
            if ( end == length ) {
                break; 
            }                
        }
        // System.out.println ( "end   = " + String.valueOf ( end   ));
        attribute = Double.valueOf
                    ( new String (expr, start, end - start) ).doubleValue();
        // System.out.println ( "attribute   = " + attribute );
        start = end;
    } else {
        token = (short)  expr [start];
        switch ( token ) {
            case '+' :
            case '-' :
            case '*' :
            case '/' :
                attribute = token;
        }                               // do not need the other operators
        switch ( token ) {
            case '+' :
                token = SlkConstants.PLUS_;
                break;
            case '-' :
                token = SlkConstants.MINUS_;
                break;
            case '*' :
                token = SlkConstants.STAR_;
                break;
            case '/' :
                token = SlkConstants.SLASH_;
                break;
            case '^' :
                token = SlkConstants.CARET_;
                break;
            case '(' :
                token = SlkConstants.LPAREN_;
                break;
            case ')' :
                token = SlkConstants.RPAREN_;
                break;
        }   
        ++start;
    }

    return  token;
}

};
